package main.java.study.step02;

/**
 * @author liuwenxiu
 * @Description:
 * @date 2022-7-13 19:24
 */
public class FinalVariableDemo {

    private String name;
    
    private final Integer age = 10;  // error - Variable 'age' might not have been initialized

//    public FinalVariableDemo(Integer age) {
//        this.age = age;
//    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "FinalVariableDemo{" +
                "name='" + name + '\'' +
                '}';
    }

    public static void main(String[] args) {
        
        final int c;
        c = 1;
//        c = 2;
        
        // final修饰局部变量
        final int a = 10;
        //a = 20; //error - Cannot assign a value to final variable 'a'
        
        final FinalVariableDemo demo = new FinalVariableDemo();
        System.out.println(demo);
        demo.setName("tom");
        System.out.println(demo);
        FinalVariableDemo demo1 = new FinalVariableDemo();
//        demo = demo1;   //error - Cannot assign a value to final variable 'demo'
    }
}
